package com.xing.util;

import java.util.Calendar;
import java.util.Date;
import java.util.Locale;

import android.app.Activity;
import android.app.DatePickerDialog;
import android.content.Context;
import android.content.Intent;
import android.text.Editable;
import android.text.TextWatcher;
import android.view.Gravity;
import android.view.KeyEvent;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.DatePicker;
import android.widget.EditText;
import android.widget.ImageView;
import android.widget.TextView;
import android.widget.Toast;

/**
 * view工具类
 * @author xing
 *
 */
public class ViewUtil {
	
	public static String toastWords = "搜过关键字不能为空!";

    /**
     * 显示日期对话框，并得到日期
     */
    public static void showDatePickerDialog(Context context,final TextView textView){
    	Calendar d = Calendar.getInstance(Locale.CHINA);
    	//创建一个日历引用d，通过静态方法getInstance() 从指定时区 Locale.CHINA 获得一个日期实例
    	Date myDate=new Date();
    	//创建一个Date实例
    	d.setTime(myDate);
    	//设置日历的时间，把一个新建Date实例myDate传入
    	int year=d.get(Calendar.YEAR);
    	int month=d.get(Calendar.MONTH);
    	int day=d.get(Calendar.DAY_OF_MONTH);
    	
    	DatePickerDialog date = new DatePickerDialog(context,2,new DatePickerDialog.OnDateSetListener() {
			
			@Override
			public void onDateSet(DatePicker view, int year, int monthOfYear,
					int dayOfMonth) {
				// TODO Auto-generated method stub
				textView.setText(Integer.toString(year) + "-" +
					    Integer.toString(monthOfYear+1) + "-" + 
					    Integer.toString(dayOfMonth));
			}
		}, year, month, day);
    	date.show();
    }
    
    /**
     * 显示toast
     * @param context
     * @param info
     */
    public static void showToast(Context context, String info){
		try {
			Toast toast = Toast.makeText(context, info, Toast.LENGTH_SHORT);
			toast.setGravity(Gravity.CENTER, 0, 0);
			toast.show();
		} catch (Exception e) {
		}
	}
    
   
}
